package cn.yang.domain.credit.model.aggregate;

import cn.yang.domain.award.model.valobj.TaskStateVO;
import cn.yang.domain.credit.event.CreditAdjustSuccessMessageEvent;
import cn.yang.domain.credit.model.entity.CreditAccountEntity;
import cn.yang.domain.credit.model.entity.CreditOrderEntity;
import cn.yang.domain.credit.model.entity.TaskEntity;
import cn.yang.domain.credit.model.valobj.TradeNameVO;
import cn.yang.domain.credit.model.valobj.TradeTypeVO;
import cn.yang.types.event.BaseEvent;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.RandomStringUtils;

import java.math.BigDecimal;

/**
 * @version v1.0
 * @ClassName: cn.yang.domain.credit.model.aggregate
 * @Description: TODO
 * @Author: YJ
 */
@Data
@NoArgsConstructor
@Builder
@AllArgsConstructor
public class TradeAggregate {
    private String userId;
    private CreditAccountEntity creditAccount;
    private CreditOrderEntity creditOrder;
    private TaskEntity taskEntity;

    public static CreditAccountEntity createCreditAccountEntity(String userId, BigDecimal adjustAmount) {
        return CreditAccountEntity.builder()
                .userId(userId)
                .adjustAmount(adjustAmount)
                .build();
    }

    public static CreditOrderEntity createCreditOrderEntity(String userId, TradeNameVO tradeNameVO, TradeTypeVO tradeTypeVO, BigDecimal tradeAmount, String outBusinessNo) {
        return CreditOrderEntity.builder()
                .userId(userId)
                .orderId(RandomStringUtils.randomNumeric(12))
                .tradeName(tradeNameVO)
                .tradeType(tradeTypeVO)
                .tradeAmount(tradeAmount)
                .outBusinessNo(outBusinessNo)
                .build();
    }

    public static TaskEntity createTaskEntity(String userId, String topic, String messageId, BaseEvent.EventMessage<CreditAdjustSuccessMessageEvent.CreditAdjustSuccessMessage> message) {
        return TaskEntity.builder()
                .userId(userId)
                .topic(topic)
                .messageId(messageId)
                .message(message)
                .state(TaskStateVO.create)
                .build();
    }
}
